<?php
    /**
     * Created by PhpStorm.
     * User: mybook-lhp
     * Date: 18/6/13
     * Time: 下午6:44
     */

    namespace app\store\api;

    use app\common\controller\API;
    use app\store\model\SliderModel;

    class Slide extends API
    {

        /**
         * 首页轮播图
         * api Get /store/Slide/lists
         *
         * @param  int $type_id 类型
         *
         * @return integer $data 200成功500失败
         * @throws \think\db\exception\DataNotFoundException
         * @throws \think\db\exception\ModelNotFoundException
         * @throws \think\exception\DbException
         */
        public function lists()
        {

            $type_id      = intval($this->request->param('type_id',0));
            $fileSlide = SliderModel::field('id,cover,typeid,url')->where(['status' => 1,'typeid' => $type_id])
                ->order('sort','desc')
                ->select();
            foreach ($fileSlide as &$item)
            {
                $item['cover'] = $item['cover'] ? get_file_path($item['cover']) : get_file_path(null);
            }
            unset($item);

            $this->result($fileSlide);
        }
    }